<template>
	<view class="listPage">
		<!-- 	<view class="listInput">
			<view class="search-card">
				<view @click="handFocus" style="line-height: 76upx;height: 76upx;">{{treeName}}</view>

			</view>
			<tree ref="company" nodeKey="fCompanyid" rangeKey="fShortname" :selectParent="selectParentTree"
				:multiple="multipleTree" :range="companyTree" :foldAll="flod" @confirm="treeConfirm"
				@cancel="treeCancel">
			</tree>
		</view> -->

		<view class="listList">
			<tki-tree ref="tkitree" :selectParent="selectParent" :multiple="multiple" :range="list" :foldAll="flod"
				rangeKey="fWtnumber" isShowS="isShows" names="fChecktype" classs="fWtUnit" fCement="fCompanyname"
				fStone2="fWtunituser" fStone3="fWtdates" fWater="fTestnote" fSand="fJudgetype" fId="fId"
				:selectId="selectId" @confirm="confirm" @cancel="cancel">
			</tki-tree>
		</view>


	</view>
</template>

<script>
	import tkiTree from '@/components/fieldTestManage/treeList/tki-tree.vue';
	// import tree from '@/components/tki-tree/tki-tree';
	export default {
		data() {
			return {
				// optionData: null, //上个页面的传参
				// 树结构
				// companyTree: [],
				// treeName: "",
				// selectParentTree: true,
				// multipleTree: false,
				flod: true,
				// 树结构
				// 选择单位
				list: [],
				multiple: false,
				selectParent: true,
				// 用户信息
				userInfo: {},
				// fBusinessscopecompanyid: "",
				selectId: null,
				dataList: []
				// MaterialTypeId: ""
			}
		},
		components: {
			tkiTree,
			// tree
		},
		onLoad(options) {
			// console.log("options",options);
			var that = this;
			// that.optionData = options;
			this.selectId = options.selectId
			uni.getStorage({
				key: 'userInfo',
				success: function(res) {
					that.userInfo = JSON.parse(res.data)
					// that.treeList();
					that.getListData(options.keyType);
				}
			})
		},
		mounted() {},
		methods: {
			// handFocus() {
			// 	this.$refs.company._show();
			// },
			// treeList() {
			// 	this.$http.getUserCompanyTreeList({
			// 			companyId: this.userInfo.companyId,
			// 			userId: this.userInfo.userId,
			// 		})
			// 		.then((res) => {
			// 			if (res.errcode == 0) {
			// 				var treeData = this.tranListToTreeData(
			// 					res.data.userCompanyTreeList
			// 				);
			// 				this.companyTree = treeData; //机构树
			// 				console.log(this.companyTree);
			// 				if (treeData[0].children == undefined) {
			// 					this.treeName = treeData[0].fShortname;
			// 					this.treeConfirm(treeData);
			// 					this.$refs.company._hide()
			// 				} else {
			// 					var that = this
			// 					uni.getStorage({
			// 						key: 'userInfo',
			// 						success: function(res) {
			// 							that.userInfo = JSON.parse(res.data)
			// 							that.dataList.fCompanyid = that.userInfo.companyId;
			// 							that.getListData(that.dataList);
			// 						}
			// 					})

			// 				}

			// 			} else {
			// 				uni.showToast({
			// 					title: "获取机构树失败",
			// 					icon: 'none',
			// 					duration: 2000
			// 				});
			// 				return false;
			// 			}
			// 		})

			// },
			// tranListToTreeData(data) {
			// 	let result = [];
			// 	if (!Array.isArray(data)) {
			// 		return result;
			// 	}
			// 	// 清除已存在的children 重新赋值
			// 	data.forEach((item) => {
			// 		delete item.children;
			// 	});

			// 	let map = {};
			// 	data.forEach((item) => {
			// 		map[item.fCompanyid] = item;
			// 	});

			// 	data.forEach((item) => {
			// 		let parent = map[item.fParentid];
			// 		if (parent) {
			// 			(parent.children || (parent.children = [])).push(item);
			// 		} else {
			// 			result.push(item);
			// 		}
			// 	});
			// 	return result;
			// },
			// treeConfirm(e) {
			// 	this.treeName = e[0].fShortname;
			// 	this.getListData(e[0].fCompanyid);
			// },
			// treeCancel() {},

			getListData(data) {
				var isShows = false
				var that = this;
				var data = {
					fCompanyid: this.userInfo.fCompanyid, //左侧选中组织机构id
					userId: this.userInfo.userId, //查询待办或已办时传 列表页查询不传
					keyType: data, // 上方查询条件样品种类
					taskNumber: "", // 上方查询条件进场编号
					page: 1, //当前页码
					pageSize: 50, //每页显示条数
					modelType: "2", // 查看：传2
					startDates: "", //进场开始时间
					endDates: "", //进场结束时间
					fProjectposition: ""
				}

				this.$http.getFieldtestCheckWitnessPageList(data).then(res => {
					if (res.errcode == 0) {
						res.data.pageInfo.list.map((item) => {
							item.isShows = false
						})
						that.list = res.data.pageInfo.list;
					} else {
						console.log("接口报错")
					}
				}, (err) => {
					uni.showToast({
						title: "获取数据失败",
						icon: 'none',
						duration: 2000
					});
				})

			},
			toggle: function(item) {
				// console.log("toggle", item);
				item.show = !item.show;
			},
			// 取消回调事件
			cancel(e) {
				// console.log(e)
				uni.navigateBack({
					delta: 1
				})
			},
			// // 显示树形选择器
			// showTree() {
			// 	console.log("showTree");
			// 	this.$refs.tkitree._show();
			// },
			// 确定回调事件
			confirm(e) {
				var that = this
				if (e[0] != undefined) {
					var editItem = e[0]

					//// App
					let pages = getCurrentPages(); // 获取当前页面栈的实例，以数组形式按栈的顺序给出，第一个元素为首页，最后一个元素为当前页面。
					let prevPage = pages[pages.length - 2]; //上一页页面实例
					prevPage.$vm.otherFun(editItem); //重点$vm  下个页面接数据函数
					uni.navigateBack();
					//// App


				} else {
					uni.showToast({
						title: "请选择进场材料",
						icon: 'none',
						duration: 2000
					})
				}
			},

		}
	}
</script>

<style lang="less" scoped>
	.listPage {
		width: 100%;
		height: 100%;
		background-color: #fff;
		overflow: hidden;

		.listInput {
			width: 100%;
			height: 100upx;

			.search-card {
				margin-top: 30upx;
				width: 100%;
				height: 100%;
				padding: 10upx;
				background: #E4E7ED;
				border: 1px solid #e2e2e2;
				border-radius: 40upx;

				input {
					width: 100%;
					height: 100%;
					display: flex;
					align-items: center;
					justify-content: center;
				}
			}
		}

		.listList {
			width: 100%;
			height: calc(100% - 130upx);
			overflow-y: auto;
		}
	}
</style>
